package me.weijing.common.widget;

import me.weijing.common.R;
import me.weijing.common.model.Police;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

public class MapPoliceView extends FrameLayout {

    private TextView mPoliceName;
    private ImageView mPoliceLever;
    private ImageView mPoliceAvatar;
    private Police police;

    public MapPoliceView(Context context) {
        this(context, null, 0);
    }

    public MapPoliceView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public void setPoliceView(Police polic) {
        this.police = polic;
        mPoliceAvatar.setImageResource(R.drawable.map_jiaojing_icon);
        if (police.getNick() != null) {
            mPoliceName.setText(polic.getNick());
        }
        int star = police.getStar();
        if (star == 0) {
            mPoliceLever.setImageResource(R.drawable.map_pingfen0);
        } else if (star == 1) {
            mPoliceLever.setImageResource(R.drawable.map_pingfen1);
        } else if (star == 2) {
            mPoliceLever.setImageResource(R.drawable.map_pingfen2);
        } else if (star == 3) {
            mPoliceLever.setImageResource(R.drawable.map_pingfen3);
        } else if (star == 4) {
            mPoliceLever.setImageResource(R.drawable.map_pingfen4);
        } else if (star == 5) {
            mPoliceLever.setImageResource(R.drawable.map_pingfen5);
        }
    }

    public MapPoliceView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.map_police, this, true);
        mPoliceLever = (ImageView) findViewById(R.id.map_police_lever);
        mPoliceName = (TextView) findViewById(R.id.map_police_name);
        mPoliceAvatar = (ImageView) findViewById(R.id.map_police_avatar);
    }

    public Police getPolice() {
        return police;
    }
}
